FROM golang:alpine AS builder
LABEL stage=gobuilder

# 为我们的镜像设置必要的环境变量
ENV GO111MODULE=on \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64 \
	GOPROXY="https://goproxy.cn,direct"

WORKDIR /home/user1/go/src/gitee/go-fast
COPY . .
COPY config.yaml  /app/config.yaml
RUN go build -ldflags="s w" o  /app/backend ./main.go

# 多阶段构建
# package docker image
FROM alpine:latest
LABEL authors="test"
WORKDIR /app

RUN mkdir "logs"
COPY --from=builder /app/backend /app/backend
COPY --from=builder /app/config.yaml /app/config.yaml

# 声明服务端口
EXPOSE 8080
# 启动容器时运行的命令
CMD ["./backend"]